﻿using DB.Dapper;
using Orther.Model.param;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;

namespace Orther.Service.Miyao
{
    public class MxPeijianService
    {
        private string mainSql = @"select b.pid as pjPid,b.pname,b.chexing,a.*  from qx_mx_peijian a 
            left join qx_peijian b on a.pid=b.Id  where 1=1 ";  
            //and a.nrId='1192c638-10fb-42a6-9949-7a5bb6690394'";
        public async Task<List<qx_mx_peijian>> GetList(MxPeijianParam param, int? topNum)
        {
            FilterClass filterClass = this.WhereFilter(param);
            List<qx_mx_peijian> list = await DapperUtilsForMysql.queryList<qx_mx_peijian>(mainSql, filterClass.parameters, "CreateDate asc", filterClass.where, topNum);
            for(int i = 0; i < list.Count; i++)
            {
                if (list[i].notselectdata == 1)
                {
                    list[i].pjPid = list[i].mxpjid;
                    list[i].pname = list[i].mxpname;
                    list[i].chexing = list[i].mxchexing;
                }
            }
            
            return list;
        }


        private FilterClass WhereFilter(MxPeijianParam param)
        {
            FilterClass filterClass = new FilterClass();

            if (param.nrId != null)
            {
                filterClass.where = filterClass.where + " and a.nrId=@nrId ";
                filterClass.parameters.Add("@nrId", param.nrId);
            }

            return filterClass;
        }

    }
}
